// components/authorization/index.js
Component({
  data: {
    isLogin: false
  },
  lifetimes: {
    attached() {
      // 登录状态
      const token = getApp().token
      // 记录登录状态 控制该组件的显示与隐藏
      this.setData({
        isLogin: !!token
      })
      if (!this.data.isLogin) {
        const pageStack = getCurrentPages()
        // console.log(pageStack);
        const currentPage = pageStack[pageStack.length - 1]
        // console.log(currentPage);
        wx.redirectTo({
          url: `/pages/login/index?returnUrl=/${currentPage.route}`
        })
      }
    }
  }
})
